#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1e6 + 10;

int n, m;
int bel[N], scc, low[N], dfn[N], tim, stk[N], top;
vec G[N], T[N];
vec pot[N];
bool vis[N];

void dfs(int x) {
	vis[x] = true; stk[++top] = x; low[x] = dfn[x] = ++tim;
	for(auto y : G[x])
		if(!dfn[y]) dfs(y), chkmin(low[x], low[y]);
		else if(vis[y]) chkmin(low[x], dfn[y]);
	if(low[x] == dfn[x]) {
		scc++; int y;
		do { y = stk[top--]; vis[y] = false; bel[y] = scc; pot[scc].eb(y);
			/*cerr << y << " " << scc << endl; */ } while(y ^ x);
	}
}

int main() {
#ifdef YJR_2333_TEST
	freopen("1.in", "r", stdin);
#endif
	n = in, m = in; rep(i, 1, m) { int u = in, v = in; G[v].eb(u); }
	rep(i, 1, n) if(!dfn[i]) dfs(i);
	rep(x, 1, n) for(auto y : G[x]) if(bel[y] != bel[x]) T[bel[y]].eb(bel[x]);
	vec ans; memset(vis, 0, sizeof vis); //cerr << scc << endl;
	rep(i, 1, scc) {
		if(!vis[i]) {
			sort(pot[i].begin(), pot[i].end());
			ans.eb(pot[i].front()); vis[i] = true;
		} for(auto v : T[i]) vis[v] = true;
	}
	sort(ans.begin(), ans.end());
	for(auto v : ans) printf("%d\n", v);
	return 0;
}
